<%--
 *  File:    DataUninstall.jsp
 *  @Author: TerryCui
 *  Date:    2010/07/31
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DataUninstall"); 
  //init param
  String strModuleName = "CM";
  String privilegeCode = "E0311,E0312,E0313";
  String contextPath = request.getContextPath();
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DataUninstall</title>
<PageFlow:CheckPageFlow pageName="p_datauninstall"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/FuncLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<script>
<%
	Vector errorcode = (Vector)session.getAttribute("errorcode");
	String messageDesc = "";
	if(errorcode != null){
		for(int e = 0;e < errorcode.size();e++){
			HashMap errHash = (HashMap)errorcode.elementAt(e);
			String messagecode = (String)errHash.get("messagecode");
			messageDesc = messageDesc + (String)errHash.get("s1");
			messageDesc = messageDesc + (String)message.getMessageDesc(messagecode) + "\\n";
		}
	}
	if(!messageDesc.equals("")){
		session.removeAttribute("errorcode");
%>
		alert("<%=messageDesc%>");
<%}%>
function page_checkall(){
	var allcheck = cform.checkall;
	var allfile = document.getElementsByName("fileids");
	for(var i = 0 ; i < allfile.length;i++){
		allfile[i].checked = allcheck.checked;
	}
}

function page_summary(actionvalue,orderbyname){
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DataUninstall.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function page_detail(datafilepk){
	var processtype = cform.processtype.value;
	if(popwindow!=null)
		popwindow.close();
	popwindow = window.open('DataUninstallDetail.jsp?<%= OvalTools.randomURL() %>&processtype=' + processtype + '&datafilepk=' + datafilepk,'newwindow', 'height=380, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

var popwindow;

function page_selectProvince(){
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}

function page_setRegion(code,name){
  if(code != document.cform.regioncode.value)
  {
    document.cform.citycode.value = "";
    document.cform.cityname.value = "";
  }
  document.cform.regioncode.value = code;
  document.cform.regionname.value = name;
  if (popwindow != null)
    popwindow.close();
}

function page_selectCity(){
  var regioncode = document.cform.regioncode.value;
  if(regioncode=="" || regioncode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
    return;
  }
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN&regioncode=' + regioncode,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function page_setCity(code,name){
  document.cform.citycode.value = code;
  document.cform.cityname.value = name;
  if (popwindow != null)
    popwindow.close();
}

function page_setOrg(id,name,code){
  document.cform.parternerid.value = id;
  document.cform.parternercode.value = code;  
  document.cform.parternername.value = name;
  var remote = window.open("","newwindow");
  if (remote != null)
    remote.close();
}

function page_cleancode(type){
	var  datahandler = new  DataHandler();
	
	if(type == 'region'){
		if(cform.regioncode.value == ''){
			cform.regioncode.value = '';
			cform.regionname.value = '';
			cform.citycode.value = '';
			cform.cityname.value = '';	
		}else{
			datahandler.add_params("regioncode" , cform.regioncode.value);
			datahandler.getResult("regioncode","cform.regioncode"); 
			datahandler.getResult("regionname","cform.regionname"); 
			datahandler.add_job("j_getregionbycode");
		}
	} 

	if(type == 'city'){
		if(cform.regionname.value == "" || cform.regionname.value == -1){
			alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
			cform.citycode.value = '';
			cform.cityname.value = '';		  
			return;
		}
		
		if(cform.citycode.value == ''){
			cform.citycode.value = '';
			cform.cityname.value = '';
		}else{
			datahandler.add_params("regioncode" , cform.regioncode.value);
			datahandler.add_params("citycode" , cform.citycode.value);
			datahandler.getResult("citycode","cform.citycode"); 
			datahandler.getResult("cityname","cform.cityname"); 
			datahandler.add_job("j_getcitybycode");
		}			
	}else if(type == 'parterner'){
		if(cform.parternercode.value == ''){
			cform.parternercode.value = '';
			cform.parternername.value = '';
			cform.parternerid.value = '';
		}else {
			datahandler.add_params("orgcode" , cform.parternercode.value);
			datahandler.getResult("orgcode","cform.parternercode"); 
			datahandler.getResult("orgname","cform.parternername"); 
			datahandler.getResult("orgid","cform.parternerid"); 
			datahandler.add_job("j_getorgbycode");
		}		
	}

	datahandler.runDataHandler();	
}

function checkdate() {
	var startdate = dateTransform(cform.startdate.value, "yyyy-MM-dd", "yyyy-MM-dd");
	var enddate = dateTransform(cform.enddate.value, "yyyy-MM-dd", "yyyy-MM-dd");
	if (startdate < 0) {
		alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE", label.getLabelName("L_BeginDate")) %>");
		cform.startdate.focus();
		return false;
	}
	if (enddate < 0) {
		alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE", label.getLabelName("L_EndDate")) %>");
		cform.enddate.focus();
		return false;
	}
	if (!isEmpty(cform.startdate.value) && !isEmpty(cform.enddate.value) && startdate > enddate) {
		alert("<%= message.getMessageDesc("VALUE_MUST_LESSTHAN", label.getLabelName("L_BeginningDate"), label.getLabelName("L_EndingDate")) %>");
		cform.enddate.focus();
		cform.enddate.select();
		return false;
	}
	return true;
}

function page_uninstall(){
	if(nullChecked(document.cform.fileids,document.cform.numrows.value)){
		alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD") %>");
		return;
	}

	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_UNINSTALL") %>"))
		return;	
	
	cform.actionname.value = "uninstall";
	cform.target = "_self";
	isRunning = true;
	cform.submit();
}

function page_datareback(){
	if(nullChecked(document.cform.fileids,document.cform.numrows.value)){
		alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD") %>");
		return;
	}

	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_UNINSTALL") %>"))
		return;	
	
	cform.actionname.value = "datareback";
	cform.target = "_self";
	isRunning = true;
	cform.submit();
}
</script>
</head>
<body >
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<% //--------------------------------------  page location --%>
<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_self">
	<input type="hidden" name="pagename" value="p_datauninstall">
	<input type="hidden" name="actionname">
	<custom:hidden property="processtype"/>
	<custom:hidden property="datafrequency"></custom:hidden>
	<custom:hidden property="languagecode" scope="session"/>
   <tr>
    <td> 
      <table width="100%" border="0" cellspacing="0" onkeydown="if(event.keyCode==13) page_summary('search');">  
         <tr>
          	<td class="td_right"><%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:text property="regioncode" name="searchqlparams" command="notnull" label="L_Province" size="10" onchange="page_cleancode('region')"/>
            	<a onclick="javascript:page_selectProvince();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="regionname" name="searchqlparams" readonly="true" size="20"/>
            </td>
         	<td class="td_right"><%= label.getLabelName("L_City") + label.getLabelName("L_Colon") %></td>
          	<td>
          		<custom:text property="citycode" name="searchqlparams" size="10" onchange="page_cleancode('city')"/>
            	<a onclick="javascript:page_selectCity();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="cityname" name="searchqlparams" readonly="true" size="20"/>
            </td>
         </tr>
         <tr>
         	<td class="td_right" ><%= label.getLabelName("L_Partner") + label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:text property="parternercode" name="searchqlparams" size="10" onchange="page_cleancode('parterner')"/>
            	<a onclick="popup('<%=contextPath %>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>','newwindow','height=450, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no')"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="parternername" name="searchqlparams" readonly="true" size="20"/>
            	<custom:hidden property="parternerid" name="searchqlparams"/>
            </td>
         	<td class="td_right" ><%= label.getLabelName("L_ReceiveTime") + label.getLabelName("L_Colon") %></td>
         	<td>
				<custom:text name="searchqlparams" property="startdate" size="10" dataType="date" dataFormat="yyyy-MM-dd" onblur="javascript:checkdate()"/>
				<a onclick="javascript:if(!startdate.disabled)show_calendar('cform.startdate','yyyy-MM-dd')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
				--
				<custom:text name="searchqlparams" property="enddate" size="10" dataType="date" dataFormat="yyyy-MM-dd" onblur="javascript:checkdate()"/>
				<a onclick="javascript:if(!enddate.disabled)show_calendar('cform.enddate','yyyy-MM-dd')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
         	</td>
         </tr>
         <tr>
         	<td class="td_right" ><%= label.getLabelName("L_FileName") + label.getLabelName("L_Colon") %></td>
         	<td>
         		<custom:text property="filename" name="searchqlparams" size="40"/>
         		<a href="javascript:page_summary('search')"><img src="<%= contextPath %>/images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a>
         	</td>
         	<td class="td_right" >&nbsp;</td>
         	<td>&nbsp;</td>
         </tr>
       </table>
    </td>
  </tr>
  <tr> 
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="5%" class="title_center"><custom:checkbox property="checkall" styleClass="checkbox" onclick="page_checkall()"/></td>
            <td width="*" class="title_center"><%= label.getLabelName("L_filename")%></td>
            <td width="20%" class="title_center"><%= label.getLabelName("L_Partner") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_Province") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_City") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_FileStatus") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ReceiveTime") %></td>
         </tr>
         <%
             int i = 0;
             String strClassType = new String(); 
             Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
             if(totalsummary == null) totalsummary = new Vector();
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            if(i%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
              
            i++;     
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
            <td class="title_center">
              <custom:checkbox property="datafilepk" styleClass="checkbox" name="summary" changedName="fileids"/>
            </td>
            <td><A onclick="page_detail('<custom:write property="datafilepk" name="summary"/>')"><custom:write property="filename" name="summary"/></A></td>
            <td><custom:write property="shortname" name="summary"/></td>
            <td><custom:write property="regionname" name="summary" nbsp="true"/></td>
            <td><custom:write property="cityname" name="summary" nbsp="true"/></td>
            <td><custom:write property="filestatus" name="summary" nbsp="true" dictType="Status"/></td>
            <td><custom:write property="receivedate" name="summary" nbsp="true" dataType="date" dataFormat="yyyy-MM-dd"/></td>
          </tr>
          </logic:iterate>
          <input type="hidden" name="numrows" value="<%=totalsummary.size()%>"/>
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
          <%if(i > 0){ %>
            <a onclick="page_uninstall()"><custom:button type="1" label="L_UninstallSelectedItems" imgsrc="edit.gif" border="0" style="width:80"/></a>
			&nbsp;&nbsp;
			<a onclick="page_datareback()"><custom:button type="1" label="L_ReClean" imgsrc="edit.gif" border="0" style="width:80"/></a>
          <%}else{ %>
          	&nbsp;
          <%} %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
</html>